<template>
	<view class="content">
		<u-navbar :autoBack="true" bgColor="rgba(0,0,0,0)" :fixed="true"  @click-left="$back" ></u-navbar>
		
		<image :src="'/images/qbg_02.png' | formatImgUrl" class="bei" mode=""></image>
		<view class="dingbox" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
			
			<view class="neibox">
				<view class="title">
					帮助您找到 <br>
					您需要的写手！
				</view>
				<view class="lvbg">
					<scroll-view scroll-y="true" class="huabox">
						<view class="huatitle">
							功能说明
						</view>
						<view class="xztxt">
							派单大厅是针对用户快速、精准匹配写手难的问题推出的针对性付费功能，在急需文章；短时间内无法寻找到合适写手时，用户可以通过此功能将创作需求上传至派单大厅，将有合适的写手前来匹配。
						</view>
						<view class="huatitle">
							如何使用
						</view>
						<view class="xztxt">
							已经开通派单功能的用户，可设置创作文章的费用、字数、类型、截稿时间、制作要求、对写手的等级要求等，发布需求，符合要求的写手抢单后，可自主选择合适的写手匹配下单。
						</view>
					</scroll-view>
					
				</view>
				
				
			</view>
			<view class="dibox" >
				<view class="zaibox">
					<view class="zaileft">
						<view class="dbox">
							<view class="zaititle">
								<text v-if="status==0">立即支付</text>
								<text v-if="status==1">限时开放</text>
							</view>
							<view class="text">
								开通平台派单服务
							</view>
						</view>
						
						<view class="zaitxt" v-if="status==0">
							永久开通￥{{price}}元
						</view>
						<view class="zaitxt" v-if="status==1">
							
							<text>永久开通￥{{price}}元</text>
							
						</view>
					</view>
					
					<view v-if="status==0" class="que" @click="showPay=true">
						立即支付
					</view>
					
					<view v-if="status==1" class="que" @click="go_task()">
						立即使用
					</view>
				</view>
				<view class="xiebox" @click="isRead =( isRead == 2?0:2)" :class="isRead == 1 ? 'shake-horizontal' : ''">
					<label>
						<!-- <checkbox style="transform: scale(0.7);"  :checked="isRead" /> -->
						<u-checkbox shape="circle" size="14" :checked="isRead" activeColor="#45C4B0" inactiveColor="#999" @change="changeBox"></u-checkbox>
					</label>
					<view class="xietxt">
						
						请阅读并同意：<text @click.stop="goToxie">《平台约文服务协议及指南》</text>
					</view>
				</view>
			</view>
		</view>
		
		<u-popup :show="showPay" mode="bottom" @close="showPay=false">
			<view class="custom-bot-pay">
				<view class="title">
					支付方式
				</view>
				<view class="pay-item display-flex" @tap="changeType(4)">
					<image :src="'/images/zhi.png' | formatImgUrl" mode="aspectFit" class="icon"></image>
					<text>支付宝支付</text>
					<image :src="'/images/xuanzhong.png' | formatImgUrl" mode="aspectFit" class="sel" v-if="paytype == 4"></image>
					<image :src="'/images/weixuanzhong.png' | formatImgUrl" mode="aspectFit" class="sel" v-else></image>
				</view>
				<view class="pay-item display-flex" @tap="changeType(3)">
					<image :src="'/images/wei.png' | formatImgUrl" mode="aspectFit" class="icon"></image>
					<text>微信支付</text>
					<image :src="'/images/xuanzhong.png' | formatImgUrl" mode="aspectFit" class="sel" v-if="paytype == 3"></image>
					<image :src="'/images/weixuanzhong.png' | formatImgUrl" mode="aspectFit" class="sel" v-else></image>
				</view>
		
				<view class="marginBorder" style="margin-top: 10px;"></view>
				<view class="btn" @tap="showPay=false,goPay()">
					确认支付
				</view>
			</view>
		</u-popup>
		
		<payPop :isShow="isShow"></payPop>
	</view>
</template>

<script>
	export default { 
		data() {
			return {
				showPay: false,
				paytype: 4,
				isRead: false,
				paddingBottomHeight: 0, //苹果X以上手机底部适配高度
				isShow:false,
				status:0,
				price:9.9,
				app_type:0
			}
		},
		onLoad() {

		},
		onShow() {
			this.get_status();
		},
		created() {
		   let that = this;
		   uni.getSystemInfo({
		      success: function(res) {
		         let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
		         model.forEach(item => {
		            //适配iphoneX以上的底部，给tabbar一定高度的padding-bottom
		            if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
		               that.paddingBottomHeight = 40;
		            }
		         })
		      }
		   });
				 var url = getCurrentPages() 
				 this.urlPath = '/' + url[0].route
				 
		},
		methods: {
			changeType(num){
				this.paytype = num
			},
			changeBox(e){
				console.log(e,111);
				this.isRead = e ? 2 : 0
			},
			go_task(){
				if (!this.isRead) {
					this.isReadTip()
					return
				}
				uni.navigateTo({
					url: '/task/list/orderlist'
				})
			},
			get_status(){
				let _this = this;
				this.$api.default.request('user/go_list_che',{}, 'POST', false).then((res) => {
					if (res.code) {
						_this.status = res.data;
						_this.price = res.price
					}
				})
			},
			goToxie() {
				uni.navigateTo({
					url: '/pages/user/abount_dea?id=3' 
				})
			},
			hidePay(e){
				console.log(e)
			},
			goPay(){
				
				
				if (!this.isRead) {
					this.isReadTip()
					return
				}
				uni.showLoading({
					title: '加载中',
					mask:true
				});
				//加载中
				
				var prams = {}
				prams['order_type'] = 2
				prams['pay_type'] = this.paytype
				// prams['fid'] = this.list[this.navIndex].id
				prams['price'] = this.price
				// #ifdef APP
					prams["app_type"] = this.paytype;
				// #endif
				let that = this;
				
				this.$api.default.request('order/createvip', prams, 'POST', false).then((res) => {
					uni.hideLoading()
					if (res.code) {
						uni.requestPayment({
						    provider: this.paytype == 4 ? 'alipay' : 'wxpay',
						    orderInfo: res.data.data, //微信、支付宝订单数据 【注意微信的订单信息，键值应该全部是小写，不能采用驼峰命名】
						    success: function (res) {
						        uni.navigateTo({
						        	url: '/task/list/orderlist'
						        })
						    },
						    fail: function (err) {
						        console.log('fail:' + JSON.stringify(err));
						    }
						});
					}
				})
				
				// this.$api.default.request('order/createvip', prams, 'POST', false).then((res) => {
				// 	if (res.code) {
				// 		this.$common.wxPay(res.data, () => {
						
				// 			that.$common.errorToShow('支付成功');
				// 			setTimeout(function(){
				// 				uni.navigateTo({
				// 					url: '/pages/user/orderdetail?id=' + this.orderInfo.id
				// 				})
				// 			}, 800); 
				// 		})
				// 	}
				// })
				
			},
			isReadTip() {
				if (!this.isRead) {
					this.$common.errorToShow('请先同意用户协议');
					this.isRead = 1
					setTimeout(() => {
						this.isRead = 0;
					}, 300)
					return
				}
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: rgba(242, 245, 242, 1);
	}
	.content {
		position: relative;
		padding: 102rpx 0;
		.bei{
			width: 100%;
			height: 100vh;
			position: fixed;
			left: 0;
			top: 0;
			z-index: -1;
		}
		.dingbox{
			position: fixed;
			left: 0;
			top: 0;
			width: 100%;
			padding-top: 100px;
			.neibox{
				padding: 0 75rpx;
				.title{
					font-size: 72rpx;
					font-weight: bold;
					letter-spacing: 0px;
					line-height: 104rpx;
					padding-bottom: 48rpx;
					color: #45C4B0;
				}
				.lvbg{
					border-top-left-radius: 30px;
					border-top-right-radius: 30px;
					// height: 788rpx;
					height: calc(100vh - 175px);
					padding-top: 48rpx;
					background: #45C4B0;
					box-shadow: 0px 4px 10px 0px #45C4B0,inset 0px 4px 10px 0px rgba(255, 255, 255, 0.3);
					position: relative;
					
					.huabox{
						position: relative;
						z-index: 22;
						padding: 0 48rpx;
						width: 520rpx;
						height: 814rpx;
						.huatitle{
							padding-bottom: 6rpx;
							font-size: 36rpx;
							font-weight: bold;
							line-height: 40rpx;
							letter-spacing: 0px;
							color: #FFFFFF;
							padding-bottom: 12rpx;
						}
						.xztxt{
							font-size: 24rpx;
							letter-spacing: 0em;
							color: #FFFFFF;
							line-height: 48rpx;
							padding-bottom: 75rpx;
							font-weight: 500;
						}
					}
				}
			}
			.dibox {
				position: fixed;
				bottom: 0;
				left: 0;
				z-index: 222;
				// position: relative;
				background-color: #ffffff;
				padding: 20rpx 66rpx 20rpx 54rpx;
				.zaibox {
					width: 630rpx;
					height: 80rpx;
					border-radius: 12px;
					background: #3D3D3D;
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin: 0 auto 10rpx;
			
					.zaileft {
						padding: 0 20rpx;
			
						.dbox {
							display: flex;
							align-items: center;
			
							.zaititle {
			
								font-size: 28rpx;
								font-weight: bold;
								background: linear-gradient(293deg, #45C4B0 -5%, #56E8B5 128%);
								-webkit-background-clip: text;
								-webkit-text-fill-color: transparent;
								background-clip: text;
								text-fill-color: transparent;
			
							}
			
							.text {
								font-size: 28rpx;
								font-weight: bold;
								color: #FFFFFF;
								padding-left: 8rpx;
							}
						}
			
						.zaitxt {
							font-size: 20rpx;
							font-weight: normal;
							letter-spacing: 0px;
							color: #999999;
							text{
								text-decoration:line-through
							}
						}
					}
			
					.que {
						width: 190rpx;
						height: 80rpx;
						border-radius: 10px;
						opacity: 1;
						background: #45C4B0;
						font-size: 24rpx;
						font-weight: bold;
						color: #FFFFFF;
						text-align: center;
						line-height: 80rpx;
					}
				}
			
				.xiebox {
					display: flex;
					align-items: center;
					justify-content: center;
					padding-bottom: 10rpx;
					.xietxt {
						font-size: 20rpx;
						font-weight: bold;
						color: #999999;
			
						text {
							font-size: 20rpx;
							font-weight: bold;
							color: #45C4B0;
							padding: 0 10rpx;
						}
					}
				}
			}
		}
		
	}
</style>